<?php 
include 'include/init.php'; 
include $_SERVER['DOCUMENT_ROOT'].'/fr/include/require_login.php';
include $_SERVER['DOCUMENT_ROOT'].'/fr/include/fonctions.php';

function splitcar($car){
	$str = "";
	$arr = explode(".", $car);
	$str = implode("", $arr);
	$arr = explode(" ", $str);
	$str = implode("", $arr);
	return $str;
}

function random($car) {
	$string = "";
	$chaine = "abcdefghijklmnpqrstuvwxy".splitcar(microtime());
	srand((double)microtime()*1000000);
	for($i=0; $i<$car; $i++) {
		$string .= $chaine[rand()%strlen($chaine)];
	}
	return $string;
}

$uid = random(12);

if($q=="pay"){
	$_SESSION['com_ref'] = $_POST['order_ref'];
	$_SESSION['com_id'] = md5(uniqid(rand(), true));
	mysql_query("INSERT INTO `command` (
	`com_id`, `com_ref`, `user_id`, `com_price`, `com_statut`, `com_date`, `com_liv`, `com_pay`)
	VALUES ('".$_SESSION['com_id']."', '".$uid."', '".$_SESSION['user_id']."', '".$_SESSION['com_total']."', 'En cours de traitement', NOW(), '".$_SESSION['com_liv']."', '".$_SESSION['com_pay']."');");
	
	$q1 = mysql_query("SELECT * FROM `cart` WHERE com_id = '0' AND user_id = '".$_SESSION['user_id']."'");
	while ($r1 = mysql_fetch_array($q1) ){
		mysql_query("INSERT INTO `cart` (`cart_id`, `user_id`, `com_id`, `pro_id`, `pro_quantity`)
		VALUES ('".$_SESSION['com_id'].$r1['pro_id']."', '".$_SESSION['user_id']."', '".$_SESSION['com_id']."', '".$r1['pro_id']."', '".$r1['pro_quantity']."');");
	}
	header("location: /fr/payvalid.php" );
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="expires" content="-1">
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<? include $_SERVER['DOCUMENT_ROOT'].'/fr/include/meta.php'; ?>
	<meta name="description" content="Herbes de Chine : Paiement par chèque" />
	<title>Herbes de Chine : Paiement par chèque</title>
	<link href="/fr/css/common.css" rel="stylesheet" type="text/css" />
	<link href="/fr/css/inside.css" rel="stylesheet" type="text/css" />
	<script language="javascript" type="text/javascript" src="/fr/js/static.js"></script>
</head>
<body>
	<? include 'include/header.php'; ?>
    <div id="tools">
    	<table>
        	<tr>
            	<td id="chemin"><a href="/fr/index.php">Accueil</a> > <a href="/fr/monpanier.php">Mon panier</a> > <a href="/fr/validation.php">Valider ma commande</a> > Paiement par chèque</td>
                <td id="search">
					<? include 'include/displaytoolbar.php'; ?>

				</td>
            </tr>
        </table>
    </div>
    <table class="widescreen">
		<tr class="top"><td colspan="2"></td></tr>
	    <tr class="middle"><td class="content">
	<!-- // Ma commande //-->
			<table>
				<tr>
					<td colspan="3"><h2>Paiement par chèque</h2></td>
				</tr>
				<tr class="ligne">
					<td class="cheque_t1" rowspan="11">Notre équipe traitons toute commande passée sur le site dès réception et encaissement du paiement. Nous restons évidemment à votre disposition pour toute question et information sur le site. </td>
					<td class="justify" colspan="2"><span class="tooltip">Veuillez envoyer votre chèque en suivant les indications suivantes :</span></td>
				</tr>
				<tr>
					<td colspan="2" class="bar"><img src="/img/common/lightgreybar.gif" alt="" /></td>
				</tr>
				<tr class="imp">
					<td width="25%" class="left">Adresse</td>
					<td width="25%" class="right">Herbes de Chine<br />29 rue Robespierre<br />77340 Pontault Combault</td>
				</tr>
				<tr>
					<td colspan="2" class="bar"><img src="/img/common/lightgreybar.gif" alt="" /></td>
				</tr>
				<tr class="imp">
					<td width="25%" class="left">À l'ordre de </td>
					<td width="25%" class="right">Herbes de Chine</td>
				</tr>
				<tr>
					<td colspan="2" class="bar"><img src="/img/common/lightgreybar.gif" alt="" /></td>
				</tr>
				<tr class="imp">
					<td class="left">Montant</td>
					<td id="total" class="price right"><? echo $_SESSION['com_total'] ?> €&nbsp;</td>
				</tr>
				<tr>
					<td colspan="2" class="bar"><img src="/img/common/lightgreybar.gif" alt="" /></td>
				</tr>
				<tr>
					<td></td>
					<td class="addcart aright"><a href="?q=pay"><img src="/img/common/valid_payment.gif" alt="Continuer" /></a></td>
				</tr>
				<tr><td colspan="2">&nbsp;</td></tr>
			</table>
		</td></tr>
		<tr class="bottom"><td colspan="2"></td></tr>
	</table>
	<? include 'include/footer.php'; ?>
</body>
</html>
